package com.optionexplorer.servlets;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;

import com.optionexplorer.strategies.ShortCallShortPutStrategy;
import com.optionexplorer.util.StringUtils;

public class Analyzer extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException {
		
		String quoteStr = req.getParameter("q");
		String rangeStr = req.getParameter("range");
		String lookAheadStr = req.getParameter("ahead");

		int lookAhead = StringUtils.parseToInt(lookAheadStr, 45);
		int range = StringUtils.parseToInt(rangeStr, 15);
		
		
		ShortCallShortPutStrategy stratObj = new ShortCallShortPutStrategy(quoteStr, range, lookAhead);
		stratObj.analyze();
		JSONObject results = stratObj.getResultsJSON();
				
		resp.setContentType("text/plain");
		resp.getWriter().println(results.toJSONString());
		
		
		resp.setContentType("text/plain");	
	}

}
